package dao;

import Utils.JDBCUtils;
import beans.User;
import cn.hutool.crypto.digest.DigestUtil;
import org.apache.commons.dbutils.QueryRunner;

import java.sql.SQLException;

public class registerDao {
    public int register(User user) {
        // 连接数据库
        QueryRunner qr = new QueryRunner(JDBCUtils.getDataSource());
        int update = 0;
        try {
            update = qr.update("insert into `user`(username,`password`) values(?,?)", user.getUsername(), DigestUtil.md5Hex(user.getPassword()));
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return update;
    }
}
